/*
var UserAdminSelectedRow;
		
function onUserAdminEditorContextMenu(grid, rowIndex, e) {
    e.stopEvent();
    var coords = e.getXY();
    UserAdminContextMenu.rowRecord = grid.store.getAt(rowIndex);
    grid.selModel.selectRow(rowIndex);
    UserAdminSelectedRow=rowIndex;
    UserAdminContextMenu.showAt([coords[0], coords[1]]);
}

UserAdminContextMenu = new Ext.menu.Menu({
    id: 'UserAdminContextMenu',
	items: [
  		{ text: 'Modify this President', handler: modifyPresidentContextMenu },
  		{ text: 'Delete this President', handler: deletePresidentContextMenu },
  		'-',
  		{ text: 'Print this grid', handler: printListingContextMenu }
	]
}); 
*/

var teamAdminWindows = new Array();

MyDesktop.TeamSwitch = Ext.extend(Ext.app.Module, {
	id:'teamswitch-win',
	text: _('Team Switch'),
	iconCls: 'teamsw',
	windowId : 'TeamSwitch',
    init : function(){
        this.launcher = {
            text: this.text,
            iconCls: this.iconCls,
            handler : this.createWindow,
            windowId : this.windowId,
            scope: this
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var winname = this.windowId;
        var win = desktop.getWindow(winname);

        if(!win){
	        var ds = new Ext.data.JsonStore({
	            url: getMainUrl(),
	            method: 'POST',
	            baseParams: {action: 'system_list', op: 'team'},
	            autoLoad: false,
	            root: 'results',
	            fields:[
	            	{name: 'id'},
	                {name: 'name'}
	            ]
	        });
			
			var form = new Ext.form.FormPanel({
		        url: getMainUrl(),
		        baseParams: {action: 'team_switch'},
		        labelWidth: 70,
		        height:140,
		        waitMsgTarget: true,
		        frame: true,
		        items: [{
		        	    xtype : "fieldset",
						autoHeight : true,
						items : [
							{
								xtype: 'combo',
								fieldLabel: _('Team'),
								hiddenName: 'teamid',
								id: 'switchTeamId',
								editable: false,
								allowBlank: false,
								blankText: _('The field is required.'),
								forceSelection: true,
								triggerAction: 'all',
							   	store: ds,
							   	valueField: 'id',
							   	mode: 'remote',
							   	displayField: 'name',
							   	width: 170,
							   	loadingText: _('Please wait...'),
							   	value: cuTeamN
							}]
		        }], 
				tbar: [{
					text: _('Save'),
					tooltip: _('Save'),
					iconCls: 'save',
					handler: function() {
		                	form.initFields();
	                		if (form.getForm().isValid()) {
	                    		form.getForm().submit({ 
		                        	method:'POST', 
		                        	waitTitle: _('Saving...'), 
		                        	waitMsg: _('Saving...'),
			                        success:function(form, action){
			                        	cuTeamN = Ext.getCmp("switchTeamId").lastSelectionText;
			                        	win.close();
			                        },
			                        failure:function(form, action){ 
		                                obj = Ext.util.JSON.decode(action.response.responseText); 
		                                Ext.Msg.error(obj.error);
			                        }                   	
	                    		});
	                		}
	                	}
				}]		        	
			});  

            win = desktop.createWindow({
				id: winname,
				title: this.text,
				closable:true,
				width:300,
				height:150,
				plain:true,
				layout: 'fit',
				iconCls: this.iconCls,
				items: form
            });

        }
          
        win.show();
    },
	display : function(){
        this.createWindow();
	}
});
